<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增考勤记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-record-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">打卡时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="clockTime" id="clock_time" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" required>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">校徽Id：</label>
                <div class="col-sm-8">
                    <input name="badgeNo" class="form-control" onclick="selectStudent()" id="badgeNo" type="text" required>
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label is-required">学生Id：</label>
                <div class="col-sm-8">
                    <input name="userId" id="userId" class="form-control" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学生姓名：</label>
                <div class="col-sm-8">
                    <input name="userName" id="userName" class="form-control" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required" >学号：</label>
                <div class="col-sm-8">
                    <input name="userNo"  id="userNo" class="form-control" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <select id="status" name="status" class="form-control m-b selectpicker" th:with="type=${@dict.getType('sc_clock_in_type')}" required>
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">时间(分钟)：</label>
                <div class="col-sm-8">
                    <input name="inOutMinute" id="inOutMinute" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">类型：</label>
                <input name="userType" class="form-control" type="text" value="2">
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "school/record"
        $("#form-record-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-record-add').serialize());
            }
        }

        $("input[name='clockTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            minView: "month",
            type: 'datetime',
            autoclose: true
        });

        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#clock_time',
                type: 'datetime',
                trigger: 'click'
            });
        });

        function selectStudent(){
            var url = ctx + "school/badge/query/2";
            var options = {
                title: '选择学生信息',
                width: "800",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var table = layero.find("iframe")[0].contentWindow.$.table;
            var badgeNos = table.selectColumns("badgeNo");
            if(badgeNos.length != 1){
                $.modal.alertWarning("请选择一条记录");
                return;
            }
            var userIds = table.selectColumns("userId");
            var userNames = table.selectColumns("userName");
            var userNos = table.selectColumns("userNo");
            $('#badgeNo').val(badgeNos[0]);
            $('#userId').val(userIds[0]);
            $('#userName').val(userNames[0]);
            $('#userNo').val(userNos[0]);
            layer.close(index);
        }
    </script>
</body>
</html>